Skip to content

Make Default const and add some const Default impls #134628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 8, 2025

Conversation

estebank
Copy link
Contributor

Full list of impl const Default types:

  • ()
  • bool
  • char
  • std::ascii::Char
  • usize
  • u8
  • u16
  • u32
  • u64
  • u128
  • i8
  • i16
  • i32
  • i64
  • i128
  • f16
  • f32
  • f64
  • f128
  • std::marker::PhantomData
  • Option
  • std::iter::Empty
  • std::ptr::Alignment
  • &[T]
  • &mut [T]
  • &str
  • &mut str
  • String
  • Vec

@rustbot
Copy link
Collaborator

rustbot commented Dec 21, 2024

r? @wesleywiser

rustbot has assigned @wesleywiser.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 21, 2024
@estebank
Copy link
Contributor Author

Made this for some experiments with default field values, might as well put it somewhere visible as it seems like an obvious next step for the const traits effort.

@compiler-errors
Copy link
Member

Please make sure this is assigned to someone on @rust-lang/project-const-traits if you take this out of draft.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Dec 24, 2024

☔ The latest upstream changes (presumably #134716) made this pull request unmergeable. Please resolve the merge conflicts.

@estebank
Copy link
Contributor Author

r? @oli-obk

Let me know what would be needed to make this merge-ready.

@fee1-dead
Copy link
Member

I'd like to block this on #133999.

@fee1-dead fee1-dead added the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Dec 30, 2024
@estebank estebank added F-const_trait_impl `#![feature(const_trait_impl)]` F-default_field_values `#![feature(default_field_values)]` labels Jan 18, 2025
@estebank estebank marked this pull request as ready for review February 12, 2025 02:39
@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Feb 12, 2025

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@bors
Copy link
Collaborator

bors commented Mar 2, 2025

☔ The latest upstream changes (presumably #137752) made this pull request unmergeable. Please resolve the merge conflicts.

@apiraino
Copy link
Contributor

apiraino commented Mar 6, 2025

This was blocked on #133999 (comment) which is now closed.

@fee1-dead are you still interested in working on a follow-up to #133999 or are there other plans? Or no plans for now?

Just to get a clearer picture of the progress here :-) Thanks

cc @oli-obk

Comment on lines 243 to 247
error: function call inside of `unwrap_or`
--> tests/ui/or_fun_call.rs:409:21
|
LL | let _ = opt_foo.unwrap_or(Foo { val: String::default() });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| Foo { val: String::default() })`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this clippy lint have a check that the value is const constructable in a stable way (which would revert this output change)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, otherwise users get clippy lints they cannot address

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it the other way around: users don't get a lint to do unwrap_or_else(NowConstThing) because NowConstThing is now detected as const by clippy, even if it isn't const in stable? So it's not that the users get unactionable feedback, but rather that they don't get feedback actionable under older versions of the std. Does rustc take advantage of things that are unstably const for const folding on stable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. It's missing lint, not a false alarm. Unfortunate, but not the end of the world

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@estebank estebank added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 3, 2025
Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me with clippy lint fixed and commit squashed

estebank added 2 commits July 7, 2025 22:09
Full list of `impl const Default` types:

- ()
- bool
- char
- Cell
- std::ascii::Char
- usize
- u8
- u16
- u32
- u64
- u128
- i8
- i16
- i32
- i64
- i128
- f16
- f32
- f64
- f128
- std::marker::PhantomData<T>
- Option<T>
- std::iter::Empty<T>
- std::ptr::Alignment
- &[T]
- &mut [T]
- &str
- &mut str
- String
- Vec<T>
@oli-obk
Copy link
Contributor

oli-obk commented Jul 8, 2025

@bors r+

@bors
Copy link
Collaborator

bors commented Jul 8, 2025

📌 Commit 8f8099f has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 8, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 8, 2025
Make `Default` const and add some `const Default` impls

Full list of `impl const Default` types:

- ()
- bool
- char
- std::ascii::Char
- usize
- u8
- u16
- u32
- u64
- u128
- i8
- i16
- i32
- i64
- i128
- f16
- f32
- f64
- f128
- std::marker::PhantomData<T>
- Option<T>
- std::iter::Empty<T>
- std::ptr::Alignment
- &[T]
- &mut [T]
- &str
- &mut str
- String
- Vec<T>
bors added a commit that referenced this pull request Jul 8, 2025
Rollup of 6 pull requests

Successful merges:

 - #134628 (Make `Default` const and add some `const Default` impls)
 - #143555 (Don't mark `#[target_feature]` safe fns as unsafe in rustdoc JSON.)
 - #143600 (Update intro blurb in `wasm32-wasip1` docs)
 - #143603 (Clarify the meaning of `AttributeOrder::KeepFirst` and `AttributeOrder::KeepLast`)
 - #143620 (fix: Remove newline from multiple crate versions note)
 - #143622 (Add target maintainer information for mips64-unknown-linux-muslabi64)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jul 8, 2025
Rollup of 6 pull requests

Successful merges:

 - #134628 (Make `Default` const and add some `const Default` impls)
 - #143555 (Don't mark `#[target_feature]` safe fns as unsafe in rustdoc JSON.)
 - #143600 (Update intro blurb in `wasm32-wasip1` docs)
 - #143603 (Clarify the meaning of `AttributeOrder::KeepFirst` and `AttributeOrder::KeepLast`)
 - #143620 (fix: Remove newline from multiple crate versions note)
 - #143622 (Add target maintainer information for mips64-unknown-linux-muslabi64)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors
Copy link
Collaborator

bors commented Jul 8, 2025

⌛ Testing commit 8f8099f with merge f838cbc...

@bors
Copy link
Collaborator

bors commented Jul 8, 2025

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing f838cbc to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 8, 2025
@bors bors merged commit f838cbc into rust-lang:master Jul 8, 2025
12 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jul 8, 2025
bors added a commit that referenced this pull request Jul 8, 2025
Rollup of 6 pull requests

Successful merges:

 - #134628 (Make `Default` const and add some `const Default` impls)
 - #143555 (Don't mark `#[target_feature]` safe fns as unsafe in rustdoc JSON.)
 - #143600 (Update intro blurb in `wasm32-wasip1` docs)
 - #143603 (Clarify the meaning of `AttributeOrder::KeepFirst` and `AttributeOrder::KeepLast`)
 - #143620 (fix: Remove newline from multiple crate versions note)
 - #143622 (Add target maintainer information for mips64-unknown-linux-muslabi64)

r? `@ghost`
`@rustbot` modify labels: rollup
Copy link
Contributor

github-actions bot commented Jul 8, 2025

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 040e2f8 (parent) -> f838cbc (this PR)

Test differences

Show 204 test diffs

Stage 1

  • [ui] tests/ui/traits/const-traits/const-traits-alloc.rs: [missing] -> pass (J0)
  • [ui] tests/ui/traits/const-traits/const-traits-core.rs: [missing] -> pass (J0)

Stage 2

  • [ui] tests/ui/traits/const-traits/const-traits-alloc.rs: [missing] -> pass (J1)
  • [ui] tests/ui/traits/const-traits/const-traits-core.rs: [missing] -> pass (J1)

Additionally, 200 doctest diffs were found. These are ignored, as they are noisy.

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard f838cbc06de60819faff3413f374706b74824ca2 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. x86_64-apple-2: 3058.6s -> 3983.6s (30.2%)
  2. dist-apple-various: 9552.8s -> 7546.0s (-21.0%)
  3. x86_64-gnu-aux: 6004.0s -> 6809.0s (13.4%)
  4. dist-x86_64-musl: 7212.6s -> 8115.8s (12.5%)
  5. x86_64-apple-1: 7022.5s -> 7529.9s (7.2%)
  6. dist-sparcv9-solaris: 5306.9s -> 4928.4s (-7.1%)
  7. test-various: 4689.0s -> 5000.5s (6.6%)
  8. dist-s390x-linux: 5116.6s -> 4780.2s (-6.6%)
  9. aarch64-gnu: 6192.3s -> 6595.1s (6.5%)
  10. tidy: 70.1s -> 74.6s (6.4%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f838cbc): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
1.5% [1.5%, 1.5%] 1
Regressions ❌
(secondary)
1.5% [1.5%, 1.5%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.5% [1.5%, 1.5%] 1

Max RSS (memory usage)

Results (primary -4.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-4.2% [-4.2%, -4.2%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -4.2% [-4.2%, -4.2%] 1

Cycles

Results (primary -0.4%, secondary -4.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.3% [2.3%, 2.3%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-3.0% [-3.0%, -3.0%] 1
Improvements ✅
(secondary)
-4.2% [-4.2%, -4.2%] 1
All ❌✅ (primary) -0.4% [-3.0%, 2.3%] 2

Binary size

Results (secondary 0.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.0% [0.0%, 0.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Bootstrap: 467.351s -> 466.242s (-0.24%)
Artifact size: 372.36 MiB -> 372.32 MiB (-0.01%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-const_trait_impl `#![feature(const_trait_impl)]` F-default_field_values `#![feature(default_field_values)]` merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.